# pragma once
# include <Arduino.h>
# include <ArduinoJson.hpp>
# include <deque>

const String WORKER_NAME_OB = "OB";
const String WORKER_NAME_LED_LINER_KETING = "LINER_KT";
const String WORKER_NAME_LED_LINER_ZHUWO = "LINER_ZW";
const String WORKER_NAME_RMSW_KETING = "RMSW_KT";
const String WORKER_NAME_RMSW_KEWO = "RMSW_KW";
const String WORKER_NAME_RMSW_CIWO = "RMSW_CW";
const String WORKER_NAME_RMSW_ZHUWO = "RMSW_ZW";
const String WORKER_NAME_IDPDSW_SHUFANG = "IDPDSW_SF";
const String WORKER_NAME_IDPDSW_MENTING = "IDPDSW_MT";
const String WORKER_NAME_IDPDSW_ZHUWO = "IDPDSW_ZW";

const String WORKER_NAME = WORKER_NAME_OB;

const bool WORKER_IS_LED_LINER =    WORKER_NAME == WORKER_NAME_LED_LINER_KETING || 
                                    WORKER_NAME == WORKER_NAME_LED_LINER_ZHUWO;
const bool WORKER_IS_RMSW =     WORKER_NAME == WORKER_NAME_RMSW_KETING ||
                                WORKER_NAME == WORKER_NAME_RMSW_KEWO || 
                                WORKER_NAME == WORKER_NAME_RMSW_CIWO || 
                                WORKER_NAME == WORKER_NAME_RMSW_ZHUWO;
const bool WORKER_IS_IDPDSW =   WORKER_NAME == WORKER_NAME_IDPDSW_SHUFANG ||
                                WORKER_NAME == WORKER_NAME_IDPDSW_MENTING ||
                                WORKER_NAME == WORKER_NAME_IDPDSW_ZHUWO;

const String ACTION_SW_LINER_LED = "SW_LINER_LED";
const String ACTION_SET_PWM = "SET_PWM";
const String ACTION_CHANGE_PIN = "CHANGE_PIN";
const String ACTION_HEARTBEAT = "HEARTBEAT";
const String ACTION_CONFIG_SYNC = "CFG_SYN";

const String ACTION_PIN_SW = "PIN_SW";
const String ACTION_PIN_PWM = "PIN_PWM";
const String ACTION_PIN_NONE = "PIN_NONE";

const String ARG_KEY_CONFIG_VERSION = "VER";
const String ARG_KEY_CONFIG_DATA = "DATA";
const String ARG_KEY_CONFIG_PKG_COUNT = "PKG_CNT";
const String ARG_KEY_CONFIG_PKG_ID = "PKG_ID";

const String PIN_ACTION_UP = "UP";
const String PIN_ACTION_DOWN = "DOWN";
const String PIN_ACTION_SW = "SW";

bool is_worker_valid(String name) {
    return name.length() < 20;
}

std::deque<String> string_split(const String &s, char sp) {
    std::deque<String> ret;
    String tmp = "";
    for (char c : s) {
        if (c == sp) {
            if (tmp.length() > 0) {
                ret.push_back(tmp);
            }
            tmp = "";
        } else {
            tmp += c;
        }
    }
    if (tmp.length() > 0) {
        ret.push_back(tmp);
    }
    return std::move(ret);
}

template<typename T>
String string_join(const T& x, char sp) {
    String ret = "";
    int cnt = 0;
    for (String y : x) {
        ret += y;
        if (cnt < x.size() - 1) {
            ret += sp;
        }
    }
    return std::move(ret);
}